<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Kontraktor_ctrl extends CI_Controller {
	
	public function __construct()
	{
		parent::__construct();
		$this->load->library('auth');
		$this->load->model('kontraktor_mdl');
	}
	
	public function index()
	{
		if($this->auth->is_logged_in() == false)
		{
			redirect('login/login');
		}
		else
		{
			//set title
			$data['nama_user']=$this->session->userdata('SESS_NAMA_LENGKAP');
			$data['page_title']='Kontraktor';
			$data['view_data']=json_encode($this->kontraktor_mdl->getListKontraktor());
			$this->load->view('module/kontraktor_view',$data);
		}
	}

	function Save(){
		if( !empty( $_POST ) ) {
			if ($this->input->post('ajax')){
				$action = $this->input->post('action');
				$id= trim($this->input->post('id_kontraktor'));
				$nama= $this->input->post('nama');
				$alamat= $this->input->post('alamat');
				$telp= $this->input->post('telp_rmh');
				$hp= $this->input->post('hp');
				$email= $this->input->post('e_mail');
				$stamp= $this->input->post('dt_stamp');
				$updateId= $this->input->post('update_id');
				$data = array(
						'id_kontraktor'=>$id,
						'nama'=>$nama,
						'alamat'=>$alamat,
						'telp_rmh'=>$telp,
						'hp'=>$hp,
						'e_mail'=>$email,
						'dt_stamp'=>$stamp,
						'update_id'=>$updateId
				);
				if ($action=="A"){
					$this->kontraktor_mdl->SaveAdd($data);
				} 
			}
		}	
	}
	
	function Edit(){
		if( !empty( $_POST ) ) {
			if ($this->input->post('ajax')){
				$action = $this->input->post('action');
				$id= trim($this->input->post('id_kontraktor'));
				$nama= $this->input->post('nama');
				$alamat= $this->input->post('alamat');
				$telp= $this->input->post('telp_rmh');
				$hp= $this->input->post('hp');
				$email= $this->input->post('e_mail');
				$stamp= $this->input->post('dt_stamp');
				$updateId= $this->input->post('update_id');
				$data = array(
						'id_kontraktor'=>$id,
						'nama'=>$nama,
						'alamat'=>$alamat,
						'telp_rmh'=>$telp,
						'hp'=>$hp,
						'e_mail'=>$email,
						'dt_stamp'=>$stamp,
						'update_id'=>$updateId
				);
				if ($action=="E"){
					$this->kontraktor_mdl->SaveEdit($data);
				} 
			}
		}	
	}
	
	
	function Delete(){
		if( !empty( $_POST ) ) {
			$id=trim($this->input->post('idKont'));
			$this->kontraktor_mdl->Delete($id);
		}		
	}
	
	function Refresh(){
		// get data baru/reload data from database
		$data['view_data']=json_encode($this->kontraktor_mdl->getListKontraktor());
		$this->load->view('module/kontraktor_view',$data);
	}
	
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */